################
#PSRM: Explaining Support for Redistribution: Social Insurance Systems and Fairness
#
#Experimental Data
#Figure D 17
#
#Verena Fetscher
#July 2022
####################



##########################
#Load data file
##########################

load("dataLab_SocialInsurance_complete.Rda")


##########################
#Filter for decision-makers
##########################

dfSub<-df[df$Role==1,]



##########################
#Average transfers among decision-makers
##########################

# Provides information in main text (Section Other-Regarding Preferences Matter)
dfSub %>%
  group_by(ID) %>%
  summarize(mean= mean(give_weight))-> mydf

summary(mydf$mean)
sd(mydf$mean)
unique(length(mydf$ID))

m<-paste("median =",as.character(round(median(mydf$mean),2)), sep=" ")
y<-median(mydf$mean)+4



##########################
#Figure D.17: Average transfers by decision-makers.
##########################

mydf %>%
  group_by(ID) %>%                            
  summarize(mean = mean) %>%
  arrange(+mean) %>%                               
  mutate(group = factor(ID, ID)) %>%   
  ggplot(aes(x=group, y=mean)) +                 
  geom_bar(stat="identity", fill = "white", colour = "black")+
  geom_hline(aes(yintercept = median(mean)),linetype="dashed")+
  annotate("text", x = 30, y = y, label =  m)+
  xlab("Subject") + ylab("Inequality-reduction in %") +
  scale_y_continuous(expand = c(0, 0)) + 
  theme_bw()+
  theme(panel.border=element_blank(),axis.line=element_line(),
        legend.position="bottom",legend.text = element_text(size = 14),
        legend.title = element_text(size=14),axis.text=element_text(size=12),
        axis.title=element_text(size=14),axis.text.x = element_blank()
  )


ggsave(file="figure_d17.pdf", height = 5.83, width = 8.27, units = "in")

